<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('seUrl'))
{
	function seoUrl($string) {
        $string = strtolower($string); //Unwanted:  {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
        $string = preg_replace("/[^a-z0-9_\s-]/", "", $string); //Strip any unwanted characters
        $string = preg_replace("/[\s-]+/", " ", $string); //Clean multiple dashes or whitespaces
        $string = preg_replace("/[\s_]/", "-", $string); //Convert whitespaces and underscore to dash
        return $string;
	}
}

if ( ! function_exists('ckeditor'))
{
	function ckEditor(){
		include_once APPPATH."third_party/ckeditor/ckeditor.php";
		return new CKEditor();
	}
}

if ( ! function_exists('postImage'))
{
	function postImage($string){
		if($string)
			return 'assets/post/'.$string;
		else
			return 'assets/images/temp/post_mid_1.jpg';
	}
}

if ( ! function_exists('profilePicture'))
{
	function profilePicture($string){
		if($string)
			return base_url('assets/avatar/'.$string);
		else
			return base_url('assets/images/temp/avatar.jpg');
	}
}

if ( ! function_exists('profileThumb'))
{
    function profileThumb($img,$name,$width,$height){
		if(($img==NULL) || ($img=="") )
			$img = "avatar.jpg";
		
        $obj =& get_instance();
        $obj->load->library('image_lib');
        $obj->load->helper('url');
        $config['image_library'] = 'gd2';
        $config['source_image'] = 'assets/avatar/'.$img;
        $config['new_image'] = 'assets/avatar/thumb/'.$name.'.jpg';
        $config['width']  = $width;
        $config['height'] = $height;
        $obj->image_lib->initialize($config);
        $obj->image_lib->resize();
        return base_url($config['new_image']);
    }
}


if ( ! function_exists('thumb'))
{
    function thumb($img,$name,$width,$height){
        $obj =& get_instance();
        $obj->load->library('image_lib');
        $obj->load->helper('url');
        $config['image_library'] = 'gd2';
        $config['source_image'] = $img;
        $config['new_image'] = 'assets/post/thumb/'.$name.'.png';
        $config['width'] = $width;
        $config['height'] = $height;
        $obj->image_lib->initialize($config);
        $obj->image_lib->resize();
        return $config['new_image'];
    }
}

if ( ! function_exists('postUrl'))
{
    function postUrl($date,$id,$title){
        $date = new DateTime($date);
		return site_url('post/read'.'/'.$date->format('Y').'/'.$date->format('m').'/'.$date->format('d').'/'.$id.'/'.seoUrl($title));
    }
} 

if ( ! function_exists('trainingUrl'))
{
    function trainingUrl($date,$cat,$id,$title){
        $date = new DateTime($date);
		return site_url('training/read'.'/'.$date->format('Y').'/'.$date->format('m').'/'.$date->format('d').'/'.$cat.'/'.$id.'/'.seoUrl($title));
    }
} 

/* End of file common_helper.php */
/* Location: ./application/helpers/download_helper.php */